TARGET = main
DEBUG_FLAGS= -g -Werror -std=c++11  #-DROCKSDB_PLATFORM_POSIX


SRC_NAME = 	$(patsubst %.cpp, %, $(wildcard *.cpp))   \
            $(patsubst %.c, %, $(wildcard *.c))


BIN_NAME =  $(patsubst %.cpp, %, $(wildcard Test*.cpp)) 

CC=gcc
CXX=g++

ROCKSDB_ROOT =$(HOME)/dev/rocksdb
GTEST_ROOT = $(ROCKSDB_ROOT)/third-party/gtest-1.8.1/fused-src

INC_PATH += $(ROCKSDB_ROOT)/include $(ROCKSDB_ROOT)
LIB_PATH += $(ROCKSDB_ROOT)/
STATIC_LIBS += rocksdb_debug
STATIC_LIBS += bz2 lz4 snappy z
STATIC_LIBS += zstd  

INC_PATH += $(GTEST_ROOT)
LIB_PATH += $(GTEST_ROOT)/gtest
STATIC_LIBS += gtest_main

STATIC_LIBS += pthread dl 

CFLAGS= $(addprefix -I, $(INC_PATH)) $(DEBUG_FLAGS)
LFLAGS= $(DEBUG_FLAGS) $(addprefix -L, $(LIB_PATH))  $(addprefix -l, $(STATIC_LIBS))

OBJS=$(addsuffix .o, $(SRC_NAME))

BINS=$(addsuffix .exe, $(BIN_NAME))

all: $(TARGET)

$(TARGET): $(OBJS)
	$(CXX) -o $@ $(OBJS) $(LFLAGS) 

$(BINS): $(OBJS)

%.exe: %.o
	$(CXX) -o $@ $(OBJS) $(LFLAGS)

%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

%.o: %.cpp
	$(CXX) $(CFLAGS) -c $<

clean: 
	rm -frv $(TARGET) $(OBJS) *.o  *.db *.stream
